package interfaces.hud.spectate;

import org.fenggui.decorator.background.PlainBackground;
import org.fenggui.util.Color;

import fileHandling.language.LanguageLoader;
import fileHandling.language.interfaces.HUDText;
import logic.common.player.Player;
import interfaces.GUISource;
import interfaces.superWidgets.InterfaceLabel;
import interfaces.superWidgets.StaticContent;

public class SpectatedPlayerContent extends StaticContent implements SpectateWidget {
	
	private InterfaceLabel playerLabel;
	
	public SpectatedPlayerContent(int width, int height) {
		super(width, height);
		
		getAppearance().add(new PlainBackground(Color.LIGHT_GRAY));
		
		playerLabel = new InterfaceLabel(GUISource.middleFont);
		GUISource.setTextColor(playerLabel, Color.BLACK);
		addWidget(playerLabel);
		
		layout();
	}
	
	private void init(Player player) {
		String spec = LanguageLoader.get(HUDText.Spectating);
		playerLabel.setText(spec + ": " + player.getName());
		layout();
	}
	
	@Override
	public SpectateListener getSpectateListener() {
		return new SpectateListener() {
			@Override
			public void spectating(SpectateChangeEvent event) {
				init(event.getWatchedPlayer());
			}
		};
	}
}